package controller.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import pojo.Binhluan;
import pojo.Hoadon;
import dao.BinhluanDAO;
import dao.HoadonDAO;

/**
 * Servlet implementation class Header
 */
@WebServlet("/Pages/TrangQuanLyBinhLuan.do")
public class TrangQuanLyBinhLuan extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public TrangQuanLyBinhLuan() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");

		HttpSession session = request.getSession();

		String action = request.getParameter("action");
		String url = "";
		
		if (action.equals("TrangQuanLyBinhLuan")) {

			request.setAttribute("page", "TrangQuanLyBinhLuan");
			url = "../index.jsp";
		}
		
		
		if (action.equals("LietKeToanBo")) {

			BinhluanDAO bldao = new BinhluanDAO();
			List<Binhluan> lstBinhLuan = bldao.getList();

			request.setAttribute("listBinhLuan", lstBinhLuan);

			request.setAttribute("page", "TrangQuanLyBinhLuan");
			url = "../index.jsp";
		}
		// ------------Button----------
		if (action.equals("Xoa")) {

			String maBinhLuan = request.getParameter("maBinhLuan");

			// ĐỢi xử lý sau khi đã thêm cột vào trong CSDL

			request.setAttribute("page", "TrangQuanLyBinhLuan");
			url = "../index.jsp";
		}
		if (action.equals("Sua")) {

			String maBinhLuan = request.getParameter("maBinhLuan");

			// Xử lý sau

			request.setAttribute("page", "TrangQuanLyBinhLuan");
			url = "../index.jsp";
		}
		if (action.equals("Duyet")) {

			String maBinhLuan = request.getParameter("maBinhLuan");

			BinhluanDAO bldao = new BinhluanDAO();
			Binhluan binhluan = bldao.get(Integer.valueOf(maBinhLuan));

			binhluan.setDaduyet(true);
			bldao.saveOrUpdate(binhluan);
			
			request.setAttribute("page", "TrangQuanLyBinhLuan");
			url = "../index.jsp";
		}
		// ------------Button----------

		RequestDispatcher rd = request.getRequestDispatcher(url);
		rd.forward(request, response);
	}
}
